﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.FATEK
{
	/// <summary>
	/// 台湾永宏公司的编程口协议，此处是基于tcp的实现，地址信息请查阅api文档信息，地址可以携带站号信息，例如 s=2;D100<br />
	/// The programming port protocol of Taiwan Yonghong company, here is the implementation based on TCP, 
	/// please refer to the API information for the address information, The address can carry station number information, such as s=2;D100
	/// </summary>
	/// <remarks>
	/// 其所支持的地址形式如下：
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>内部继电器</term>
	///     <term>M</term>
	///     <term>M100,M200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输入继电器</term>
	///     <term>X</term>
	///     <term>X10,X20</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输出继电器</term>
	///     <term>Y</term>
	///     <term>Y10,Y20</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>步进继电器</term>
	///     <term>S</term>
	///     <term>S100,S200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的触点</term>
	///     <term>T</term>
	///     <term>T100,T200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的当前值</term>
	///     <term>RT</term>
	///     <term>RT100,RT200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的触点</term>
	///     <term>C</term>
	///     <term>C100,C200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的当前</term>
	///     <term>RC</term>
	///     <term>RC100,RC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>数据寄存器</term>
	///     <term>D</term>
	///     <term>D1000,D2000</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>文件寄存器</term>
	///     <term>R</term>
	///     <term>R100,R200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// </remarks>
	// Token: 0x020000AC RID: 172
	public class FatekProgramOverTcp : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化默认的构造方法<br />
		/// Instantiate the default constructor
		/// </summary>
		// Token: 0x06000C9E RID: 3230 RVA: 0x0004ABFF File Offset: 0x00048DFF
		public FatekProgramOverTcp()
		{
			base.WordLength = 1;
			base.ByteTransform = new RegularByteTransform();
			base.SleepTime = 20;
		}

		/// <summary>
		/// 使用指定的ip地址和端口来实例化一个对象<br />
		/// Instantiate an object with the specified IP address and port
		/// </summary>
		/// <param name="ipAddress">设备的Ip地址</param>
		/// <param name="port">设备的端口号</param>
		// Token: 0x06000C9F RID: 3231 RVA: 0x0004AC2D File Offset: 0x00048E2D
		public FatekProgramOverTcp(string ipAddress, int port)
		{
			base.WordLength = 1;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
			base.SleepTime = 20;
		}

		/// <summary>
		/// PLC的站号信息，需要和实际的设置值一致，默认为1<br />
		/// The station number information of the PLC needs to be consistent with the actual setting value. The default is 1.
		/// </summary>
		// Token: 0x170001ED RID: 493
		// (get) Token: 0x06000CA0 RID: 3232 RVA: 0x0004AC6B File Offset: 0x00048E6B
		// (set) Token: 0x06000CA1 RID: 3233 RVA: 0x0004AC73 File Offset: 0x00048E73
		public byte Station
		{
			get
			{
				return this.station;
			}
			set
			{
				this.station = value;
			}
		}

		/// <summary>
		/// 批量读取PLC的字节数据，以字为单位，支持读取X,Y,M,S,D,T,C,R,RT,RC具体的地址范围需要根据PLC型号来确认，地址可以携带站号信息，例如 s=2;D100<br />
		/// Read PLC byte data in batches, in word units. Supports reading X, Y, M, S, D, T, C, R, RT, RC. 
		/// The specific address range needs to be confirmed according to the PLC model, The address can carry station number information, such as s=2;D100
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <returns>读取结果信息</returns>
		// Token: 0x06000CA2 RID: 3234 RVA: 0x0004AC7C File Offset: 0x00048E7C
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<byte[]> operateResult = FatekProgramOverTcp.BuildReadCommand(this.station, address, length, false);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 2;
					if (flag3)
					{
						result = new OperateResult<byte[]>((int)operateResult2.Content[0], "Read Faild:" + SoftBasic.ByteToHexString(operateResult2.Content, ' '));
					}
					else
					{
						bool flag4 = operateResult2.Content[5] != 48;
						if (flag4)
						{
							result = new OperateResult<byte[]>((int)operateResult2.Content[5], FatekProgramOverTcp.GetErrorDescriptionFromCode((char)operateResult2.Content[5]));
						}
						else
						{
							byte[] array = new byte[(int)(length * 2)];
							for (int i = 0; i < array.Length / 2; i++)
							{
								ushort value = Convert.ToUInt16(Encoding.ASCII.GetString(operateResult2.Content, i * 4 + 6, 4), 16);
								BitConverter.GetBytes(value).CopyTo(array, i * 2);
							}
							result = OperateResult.CreateSuccessResult<byte[]>(array);
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 批量写入PLC的数据，以字为单位，也就是说最少2个字节信息，支持X,Y,M,S,D,T,C,R,RT,RC具体的地址范围需要根据PLC型号来确认，地址可以携带站号信息，例如 s=2;D100<br />
		/// The data written to the PLC in batches, in units of words, that is, at least 2 bytes of information, 
		/// supporting X, Y, M, S, D, T, C, R, RT, and RC. The specific address range needs to be based on the PLC model To confirm, The address can carry station number information, such as s=2;D100
		/// </summary>
		/// <param name="address">地址信息，举例，D100，R200，RC100，RT200</param>
		/// <param name="value">数据值</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000CA3 RID: 3235 RVA: 0x0004ADB4 File Offset: 0x00048FB4
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<byte[]> operateResult = FatekProgramOverTcp.BuildWriteByteCommand(this.station, address, value);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 2;
					if (flag3)
					{
						result = new OperateResult((int)operateResult2.Content[0], "Write Faild:" + SoftBasic.ByteToHexString(operateResult2.Content, ' '));
					}
					else
					{
						bool flag4 = operateResult2.Content[5] != 48;
						if (flag4)
						{
							result = new OperateResult<byte[]>((int)operateResult2.Content[5], FatekProgramOverTcp.GetErrorDescriptionFromCode((char)operateResult2.Content[5]));
						}
						else
						{
							result = OperateResult.CreateSuccessResult();
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.FATEK.FatekProgramOverTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000CA4 RID: 3236 RVA: 0x0004AE7C File Offset: 0x0004907C
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			FatekProgramOverTcp.<ReadAsync>d__7 <ReadAsync>d__ = new FatekProgramOverTcp.<ReadAsync>d__7();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<FatekProgramOverTcp.<ReadAsync>d__7>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.FATEK.FatekProgramOverTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000CA5 RID: 3237 RVA: 0x0004AED0 File Offset: 0x000490D0
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			FatekProgramOverTcp.<WriteAsync>d__8 <WriteAsync>d__ = new FatekProgramOverTcp.<WriteAsync>d__8();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<FatekProgramOverTcp.<WriteAsync>d__8>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 批量读取bool类型数据，支持的类型为X,Y,M,S,T,C，具体的地址范围取决于PLC的类型，地址可以携带站号信息，例如 s=2;M100<br />
		/// Read bool data in batches. The supported types are X, Y, M, S, T, C. The specific address range depends on the type of PLC, 
		/// The address can carry station number information, such as s=2;M100
		/// </summary>
		/// <param name="address">地址信息，比如X10，Y17，M100</param>
		/// <param name="length">读取的长度</param>
		/// <returns>读取结果信息</returns>
		// Token: 0x06000CA6 RID: 3238 RVA: 0x0004AF24 File Offset: 0x00049124
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<byte[]> operateResult = FatekProgramOverTcp.BuildReadCommand(this.station, address, length, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 2;
					if (flag3)
					{
						result = new OperateResult<bool[]>((int)operateResult2.Content[0], "Read Faild:" + SoftBasic.ByteToHexString(operateResult2.Content, ' '));
					}
					else
					{
						bool flag4 = operateResult2.Content[5] != 48;
						if (flag4)
						{
							result = new OperateResult<bool[]>((int)operateResult2.Content[5], FatekProgramOverTcp.GetErrorDescriptionFromCode((char)operateResult2.Content[5]));
						}
						else
						{
							byte[] array = new byte[(int)length];
							Array.Copy(operateResult2.Content, 6, array, 0, (int)length);
							result = OperateResult.CreateSuccessResult<bool[]>(Enumerable.ToArray<bool>(Enumerable.Select<byte, bool>(array, (byte m) => m == 49)));
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 批量写入bool类型的数组，支持的类型为X,Y,M,S,T,C，具体的地址范围取决于PLC的类型，地址可以携带站号信息，例如 s=2;M100<br />
		/// Write arrays of type bool in batches. The supported types are X, Y, M, S, T, C. The specific address range depends on the type of PLC, 
		/// The address can carry station number information, such as s=2;M100
		/// </summary>
		/// <param name="address">PLC的地址信息</param>
		/// <param name="value">数据信息</param>
		/// <returns>是否写入成功</returns>
		// Token: 0x06000CA7 RID: 3239 RVA: 0x0004B040 File Offset: 0x00049240
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] value)
		{
			OperateResult<byte[]> operateResult = FatekProgramOverTcp.BuildWriteBoolCommand(this.station, address, value);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					bool flag3 = operateResult2.Content[0] != 2;
					if (flag3)
					{
						result = new OperateResult((int)operateResult2.Content[0], "Write Faild:" + SoftBasic.ByteToHexString(operateResult2.Content, ' '));
					}
					else
					{
						bool flag4 = operateResult2.Content[5] != 48;
						if (flag4)
						{
							result = new OperateResult<bool[]>((int)operateResult2.Content[5], FatekProgramOverTcp.GetErrorDescriptionFromCode((char)operateResult2.Content[5]));
						}
						else
						{
							result = OperateResult.CreateSuccessResult();
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.FATEK.FatekProgramOverTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000CA8 RID: 3240 RVA: 0x0004B108 File Offset: 0x00049308
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			FatekProgramOverTcp.<ReadBoolAsync>d__11 <ReadBoolAsync>d__ = new FatekProgramOverTcp.<ReadBoolAsync>d__11();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<FatekProgramOverTcp.<ReadBoolAsync>d__11>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.FATEK.FatekProgramOverTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000CA9 RID: 3241 RVA: 0x0004B15C File Offset: 0x0004935C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] value)
		{
			FatekProgramOverTcp.<WriteAsync>d__12 <WriteAsync>d__ = new FatekProgramOverTcp.<WriteAsync>d__12();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<FatekProgramOverTcp.<WriteAsync>d__12>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000CAA RID: 3242 RVA: 0x0004B1AE File Offset: 0x000493AE
		public override string ToString()
		{
			return string.Format("FatekProgramOverTcp[{0}:{1}]", this.IpAddress, this.Port);
		}

		/// <summary>
		/// 解析数据地址成不同的永宏地址类型
		/// </summary>
		/// <param name="address">数据地址</param>
		/// <returns>地址结果对象</returns>
		// Token: 0x06000CAB RID: 3243 RVA: 0x0004B1CC File Offset: 0x000493CC
		public static OperateResult<string> FatekAnalysisAddress(string address)
		{
			OperateResult<string> operateResult = new OperateResult<string>();
			try
			{
				char c = address[0];
				char c2 = c;
				if (c2 <= 'Y')
				{
					if (c2 <= 'D')
					{
						if (c2 == 'C')
						{
							goto IL_1B9;
						}
						if (c2 != 'D')
						{
							goto IL_2EC;
						}
						goto IL_1EB;
					}
					else
					{
						if (c2 == 'M')
						{
							goto IL_123;
						}
						switch (c2)
						{
						case 'R':
							goto IL_21D;
						case 'S':
							goto IL_155;
						case 'T':
							goto IL_187;
						case 'U':
						case 'V':
						case 'W':
							goto IL_2EC;
						case 'X':
							break;
						case 'Y':
							goto IL_F1;
						default:
							goto IL_2EC;
						}
					}
				}
				else if (c2 <= 'd')
				{
					if (c2 == 'c')
					{
						goto IL_1B9;
					}
					if (c2 != 'd')
					{
						goto IL_2EC;
					}
					goto IL_1EB;
				}
				else
				{
					if (c2 == 'm')
					{
						goto IL_123;
					}
					switch (c2)
					{
					case 'r':
						goto IL_21D;
					case 's':
						goto IL_155;
					case 't':
						goto IL_187;
					case 'u':
					case 'v':
					case 'w':
						goto IL_2EC;
					case 'x':
						break;
					case 'y':
						goto IL_F1;
					default:
						goto IL_2EC;
					}
				}
				operateResult.Content = "X" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				goto IL_2FC;
				IL_F1:
				operateResult.Content = "Y" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				goto IL_2FC;
				IL_123:
				operateResult.Content = "M" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				goto IL_2FC;
				IL_155:
				operateResult.Content = "S" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				goto IL_2FC;
				IL_187:
				operateResult.Content = "T" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				goto IL_2FC;
				IL_1B9:
				operateResult.Content = "C" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				goto IL_2FC;
				IL_1EB:
				operateResult.Content = "D" + Convert.ToUInt16(address.Substring(1), 10).ToString("D5");
				goto IL_2FC;
				IL_21D:
				bool flag = address[1] == 'T' || address[1] == 't';
				if (flag)
				{
					operateResult.Content = "RT" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
				}
				else
				{
					bool flag2 = address[1] == 'C' || address[1] == 'c';
					if (flag2)
					{
						operateResult.Content = "RC" + Convert.ToUInt16(address.Substring(1), 10).ToString("D4");
					}
					else
					{
						operateResult.Content = "R" + Convert.ToUInt16(address.Substring(1), 10).ToString("D5");
					}
				}
				goto IL_2FC;
				IL_2EC:
				throw new Exception(StringResources.Language.NotSupportedDataType);
				IL_2FC:;
			}
			catch (Exception ex)
			{
				operateResult.Message = ex.Message;
				return operateResult;
			}
			operateResult.IsSuccess = true;
			return operateResult;
		}

		/// <summary>
		/// 计算指令的和校验码
		/// </summary>
		/// <param name="data">指令</param>
		/// <returns>校验之后的信息</returns>
		// Token: 0x06000CAC RID: 3244 RVA: 0x0004B51C File Offset: 0x0004971C
		public static string CalculateAcc(string data)
		{
			byte[] bytes = Encoding.ASCII.GetBytes(data);
			int num = 0;
			for (int i = 0; i < bytes.Length; i++)
			{
				num += (int)bytes[i];
			}
			return num.ToString("X4").Substring(2);
		}

		/// <summary>
		/// 创建一条读取的指令信息，需要指定一些参数
		/// </summary>
		/// <param name="station">PLCd的站号</param>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <param name="isBool">是否位读取</param>
		/// <returns>是否成功的结果对象</returns>
		// Token: 0x06000CAD RID: 3245 RVA: 0x0004B56C File Offset: 0x0004976C
		public static OperateResult<byte[]> BuildReadCommand(byte station, string address, ushort length, bool isBool)
		{
			station = (byte)HslHelper.ExtractParameter(ref address, "s", (int)station);
			OperateResult<string> operateResult = FatekProgramOverTcp.FatekAnalysisAddress(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append('\u0002');
				stringBuilder.Append(station.ToString("X2"));
				if (isBool)
				{
					stringBuilder.Append("44");
					stringBuilder.Append(length.ToString("X2"));
				}
				else
				{
					stringBuilder.Append("46");
					stringBuilder.Append(length.ToString("X2"));
					bool flag2 = operateResult.Content.StartsWith("X") || operateResult.Content.StartsWith("Y") || operateResult.Content.StartsWith("M") || operateResult.Content.StartsWith("S") || operateResult.Content.StartsWith("T") || operateResult.Content.StartsWith("C");
					if (flag2)
					{
						stringBuilder.Append("W");
					}
				}
				stringBuilder.Append(operateResult.Content);
				stringBuilder.Append(FatekProgramOverTcp.CalculateAcc(stringBuilder.ToString()));
				stringBuilder.Append('\u0003');
				result = OperateResult.CreateSuccessResult<byte[]>(Encoding.ASCII.GetBytes(stringBuilder.ToString()));
			}
			return result;
		}

		/// <summary>
		/// 创建一条别入bool数据的指令信息，需要指定一些参数
		/// </summary>
		/// <param name="station">站号</param>
		/// <param name="address">地址</param>
		/// <param name="value">数组值</param>
		/// <returns>是否创建成功</returns>
		// Token: 0x06000CAE RID: 3246 RVA: 0x0004B6DC File Offset: 0x000498DC
		public static OperateResult<byte[]> BuildWriteBoolCommand(byte station, string address, bool[] value)
		{
			station = (byte)HslHelper.ExtractParameter(ref address, "s", (int)station);
			OperateResult<string> operateResult = FatekProgramOverTcp.FatekAnalysisAddress(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append('\u0002');
				stringBuilder.Append(station.ToString("X2"));
				stringBuilder.Append("45");
				stringBuilder.Append(value.Length.ToString("X2"));
				stringBuilder.Append(operateResult.Content);
				for (int i = 0; i < value.Length; i++)
				{
					stringBuilder.Append(value[i] ? "1" : "0");
				}
				stringBuilder.Append(FatekProgramOverTcp.CalculateAcc(stringBuilder.ToString()));
				stringBuilder.Append('\u0003');
				result = OperateResult.CreateSuccessResult<byte[]>(Encoding.ASCII.GetBytes(stringBuilder.ToString()));
			}
			return result;
		}

		/// <summary>
		/// 创建一条别入byte数据的指令信息，需要指定一些参数，按照字单位
		/// </summary>
		/// <param name="station">站号</param>
		/// <param name="address">地址</param>
		/// <param name="value">数组值</param>
		/// <returns>是否创建成功</returns>
		// Token: 0x06000CAF RID: 3247 RVA: 0x0004B7D4 File Offset: 0x000499D4
		public static OperateResult<byte[]> BuildWriteByteCommand(byte station, string address, byte[] value)
		{
			station = (byte)HslHelper.ExtractParameter(ref address, "s", (int)station);
			OperateResult<string> operateResult = FatekProgramOverTcp.FatekAnalysisAddress(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append('\u0002');
				stringBuilder.Append(station.ToString("X2"));
				stringBuilder.Append("47");
				stringBuilder.Append((value.Length / 2).ToString("X2"));
				bool flag2 = operateResult.Content.StartsWith("X") || operateResult.Content.StartsWith("Y") || operateResult.Content.StartsWith("M") || operateResult.Content.StartsWith("S") || operateResult.Content.StartsWith("T") || operateResult.Content.StartsWith("C");
				if (flag2)
				{
					stringBuilder.Append("W");
				}
				stringBuilder.Append(operateResult.Content);
				byte[] array = new byte[value.Length * 2];
				for (int i = 0; i < value.Length / 2; i++)
				{
					SoftBasic.BuildAsciiBytesFrom(BitConverter.ToUInt16(value, i * 2)).CopyTo(array, 4 * i);
				}
				stringBuilder.Append(Encoding.ASCII.GetString(array));
				stringBuilder.Append(FatekProgramOverTcp.CalculateAcc(stringBuilder.ToString()));
				stringBuilder.Append('\u0003');
				result = OperateResult.CreateSuccessResult<byte[]>(Encoding.ASCII.GetBytes(stringBuilder.ToString()));
			}
			return result;
		}

		/// <summary>
		/// 根据错误码获取到真实的文本信息
		/// </summary>
		/// <param name="code">错误码</param>
		/// <returns>错误的文本描述</returns>
		// Token: 0x06000CB0 RID: 3248 RVA: 0x0004B970 File Offset: 0x00049B70
		public static string GetErrorDescriptionFromCode(char code)
		{
			switch (code)
			{
			case '2':
				return StringResources.Language.FatekStatus02;
			case '3':
				return StringResources.Language.FatekStatus03;
			case '4':
				return StringResources.Language.FatekStatus04;
			case '5':
				return StringResources.Language.FatekStatus05;
			case '6':
				return StringResources.Language.FatekStatus06;
			case '7':
				return StringResources.Language.FatekStatus07;
			case '8':
				break;
			case '9':
				return StringResources.Language.FatekStatus09;
			default:
				if (code == 'A')
				{
					return StringResources.Language.FatekStatus10;
				}
				break;
			}
			return StringResources.Language.UnknownError;
		}

		// Token: 0x0400036C RID: 876
		private byte station = 1;
	}
}
